package com.my.study.config.hook.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * <p>Bean初始化完成扩展点</p>
 * <p>InitializingBean的用法基本上与@PostConstruct一致，只不过相应的Bean需要实现afterPropertiesSet方法
 * </p>
 *
 * @author: yidujun
 * @create: 2021/04/02 16:05
 */
@Component
@Slf4j
public class InitializingBeanExampleBean implements InitializingBean {

    @Autowired
    private Environment environment;

    @Override
    public void afterPropertiesSet() throws Exception {
        String[] strings = environment.getDefaultProfiles();
        log.info("InitializingBeanExampleBean -> {}", Arrays.asList(strings));
    }
}
